#!/bin/sh

# step1. 配置参数
BASE_HOME=/data/xgz/auto-maven-compile
GIT_OCEAN=git@192.168.3.137:deepocean
GIT_URL=$GIT_OCEAN/products/5g/do-for-5g-common/
REMOTE_URL=https://gitee.com/xuguozhong/auto-complie/raw/master
WEB_APPS=/data/docker/tomcat/webapps

mkdir -p $BASE_HOME
cd $BASE_HOME
rm -rf openapi
git clone -q $GIT_OCEAN/framework/osgi-web-framework/openapi.git

mkdir template
wget -q $REMOTE_URL/template/pom-dao.xml -O template/pom-dao.xml
wget -q $REMOTE_URL/template/pom-web.xml -O template/pom-web.xml
\cp template/pom-web.xml openapi/openapi-web/pom.xml -f
\cp template/pom-dao.xml openapi/openapi-dao/pom.xml -f

cd openapi/openapi-dao

suffixs=(
    # 徐国忠
    terminal-analyze/modules/openapi-dao-do5g-terminalanalysis.git
    5GServiceAnalysis/modules/openapi-dao-do5g-serviceanalysis.git
    # 李梦伟
    network-monitor/modules/openapi-dao-do5g-networkmonitor.git
    netview/openapi-dao-do5g-networkview.git
    networkgeneral/modules/openapi-dao-do5g-share.git
    # 尹君
    residentdelimitation/modules/openapi-dao-do5g-residentdelimitation.git
    # 王基帅
    residentanalysis/modules/openapi-dao-do5g-residentanalysis.git
    # 李力博
    anchorpoint/modules/openapi-dao-do5g-anchorpoint.git
    # SA网络视图
    sanetworkview/modules/openapi-dao-do5g-networkview_sa.git
    # SA管理视图
    samanageview/modules/openapi-dao-do5g-samanageview.git
    # SA终端分析
    saterminalanalysis/modules/openapi-dao-do5g-terminalanalysis-sa.git
    # SA切片分析
    saslices/modules/openapi-dao-do5g-slices_sa.git
    # SA切片定界
    slicedelimitation/modules/openapi-dao-do5g-slicedelimitation_sa.git
)
for suffix in ${suffixs[@]}
do
    git clone -q $GIT_URL$suffix
done

cd ..
mvn clean package -DskipTests
cd openapi-web/target
unzip -o openapi-web-1.0-SNAPSHOT.jar -d openapi-web | grep lib/openapi

# 数据备份
currenttime=$(date +%Y%m%d%H%M%S)
mkdir -p $BASE_HOME/openapi-lib/$currenttime/
mkdir -p $BASE_HOME/openapi-classes/$currenttime/
\cp $WEB_APPS/ROOT/WEB-INF/lib/openapi* $BASE_HOME/openapi-lib/$currenttime/ -rf
\cp $WEB_APPS/ROOT/WEB-INF/classes/com $BASE_HOME/openapi-classes/$currenttime/ -rf

# 拷贝框架openapi-web部分
\cp classes/com $WEB_APPS/ROOT/WEB-INF/classes/ -rf
\cp classes/com $WEB_APPS-pg/ROOT/WEB-INF/classes/ -rf
\cp classes/com $WEB_APPS-sa/ROOT/WEB-INF/classes/ -rf


# 拷贝openapi-dao下的业务部分
#\cp openapi-web/BOOT-INF/lib/openapi-dao-do5g-ter* /data/docker/tomcat/webapps/ROOT/WEB-INF/lib -rf
#\cp openapi-web/BOOT-INF/lib/openapi-dao-do5g-ter* /data/docker/tomcat/webapps-pg/ROOT/WEB-INF/lib -rf
#\cp openapi-web/BOOT-INF/lib/openapi-dao-do5g-ser* /data/docker/tomcat/webapps/ROOT/WEB-INF/lib -rf
#\cp openapi-web/BOOT-INF/lib/openapi-dao-do5g-ser* /data/docker/tomcat/webapps-pg/ROOT/WEB-INF/lib -rf

\cp openapi-web/BOOT-INF/lib/openapi-dao-do5g-* $WEB_APPS/ROOT/WEB-INF/lib -rf
\cp openapi-web/BOOT-INF/lib/openapi-dao-do5g-* $WEB_APPS-pg/ROOT/WEB-INF/lib -rf
\cp openapi-web/BOOT-INF/lib/openapi-dao-do5g-* $WEB_APPS-sa/ROOT/WEB-INF/lib -rf

cd ../../..

rm -rf ./openapi.tar.gz
tar -czf openapi.tar.gz openapi-lib/$currenttime/*
wget -q $REMOTE_URL/utils/send-mail.py
python3 send-mail.py jfjqjljpomyxbidi 后端应用openapi openapi.tar.gz
rm -rf send-mail.py
rm -rf ./openapi.tar.gz

rm -rf template
rm -rf openapi

docker restart tc tc-pg tc-sa
